<?php

namespace app\admin\controller;

use think\Controller;

class Setting extends Base
{
    /**
     * 列表
     */
    public function help(){
       $service =  db('setting')->where('key','service')->find();
       $service = json_decode($service['value'],true);
       $this->assign('service',$service);
        return $this->fetch();
    }

    public function service(){
        $service = db('setting')->where('key','service')->find();
        $service = json_decode($service['value'],true);
        if(request()->isPost()){
            $post = input('post.');
            $post['content'] = trim($post['content']);
            $value = json_encode($post);
            $data = [
              'key' => 'service',
              'value' => $value
            ];
            if(!db('setting')->where('key','service')->select()){
                db('setting')->insert($data);
                return $this->success('添加成功',url('setting/help'));
            }else{
                db('setting')->where('key','service')->update($data);
                return $this->success('修改成功',url('setting/help'));
            }
        }
        $this->assign('service',$service);
        return $this->fetch();
    }

}
